package com.ihighest.app.infox.myview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ihighest.app.common.kit.SharedPreferencesKit;
import com.ihighest.app.infox.R;
import com.ihighest.app.infox.tools.MyCheckBoxListener;

public class SettingCheckboxView extends RelativeLayout {
	private TextView item;
	private CheckBox chockBox;
	public String name;
	private Context context;

	public SettingCheckboxView(Context context, AttributeSet attrs, String name, boolean icheck) {
		super(context, attrs);
		this.context = context;
		initView(context);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SettingCheckboxView);
		String itemName = a.getString(R.styleable.SettingCheckboxView_cbItemName);
		setItemName(itemName);
		// Constants.changeSize(context, this, true);
		a.recycle();
	}

	public SettingCheckboxView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		this.context = context;
		initView(context);
		// Constants.changeSize(context, this, true);
	}

	public SettingCheckboxView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SettingCheckboxView);
		String itemName = a.getString(R.styleable.SettingCheckboxView_cbItemName);
		setItemName(itemName);
		// Constants.changeSize(context, this, true);
		a.recycle();
	}

	/**
	 * 是否选中
	 * 
	 * @return
	 * 
	 * @author lkx Created at 2015-10-5 上午9:53:04
	 */
	@SuppressWarnings("unused")
	private boolean isChecked() {
		// TODO Auto-generated method stub
		return chockBox.isChecked();
	}

	/**
	 * 设置条目
	 * 
	 * @param itemName
	 * 
	 * @author lkx Created at 2015-10-5 上午9:14:08
	 */
	private void setItemName(String itemName) {
		item.setText(itemName);

	}

	public SettingCheckboxView(Context context) {
		super(context);
		this.context = context;
		initView(context);
	}

	/**
	 * 初始化绑定控件
	 * 
	 * @param context
	 * 
	 * @author lkx Created at 2015-10-5 上午8:58:56
	 */
	private void initView(Context context) {
		View view = View.inflate(context, R.layout.infox_myview_checkboxview, this);
		item = (TextView) view.findViewById(R.id.mSettingCbItem_name);
		item.setTextSize(16.0f);
		chockBox = (CheckBox) view.findViewById(R.id.mSettingCbItem_checkBox);
		// setOnclickedListener();
	}

	public void setOnclickedListener(OnCheckedChangeListener listener) {
		// MyCheckBoxListener listene = new MyCheckBoxListener() {
		//
		// @Override
		// public void saveStyle(String manme, boolean ischeck) {
		// SharedPreferencesKit.putBoolean(getContext(), name, ischeck);
		//
		// }
		//
		// };
		chockBox.setOnCheckedChangeListener(listener);
	}

	public void setOnclickedListener2() {

		MyCheckBoxListener listener = new MyCheckBoxListener() {

			@Override
			public void check(String name, boolean check) {
				SharedPreferencesKit.putBoolean(context, name, check);

			}

			@Override
			public String getName(String name) {
				// TODO Auto-generated method stub
				return null;
			}

		};

		chockBox.setOnCheckedChangeListener(listener);
	}

	/**
	 * 设置组合控件的勾选状态
	 */
	public void setChecked(boolean checked) {
		chockBox.setChecked(checked);

	}

}
